 

use "Data/Census w-restrictions.dta", clear

gen ARRA = (year == 2010 & fyend <= 630) | (year == 2011 & fyend > 630)

 gen bucket = .
 forvalues x = 1000(500)60000 {
 replace bucket = `x' if ltd_iss_all_other > `x' - 500 & ltd_iss_all_other <= `x' 
 }
 
replace bucket = bucket/1000
 
forvalues y = 2/14 {
gen bucket_`y' = bucket^`y'
}

gen Qdummy = ltd_iss_all_other <= 10000
gen bucket_Q = bucket * Qdummy

forvalues y = 2/14 {
gen bucket`y'_Q = bucket_`y' * Qdummy
}

gen bucket_alt = round((bucket/0.5) - 16)
forvalues q = 1(1)16 {
gen bucket`q' = bucket_alt == `q'
}

drop bucket_alt

keep ltd_iss_all_other id bucket* type_code Qdummy ARRA

sort bucket ARRA
by bucket ARRA: egen count = count(bucket) 

count if ltd_iss_all_other >= 0 & ARRA == 0
scalar totalcount = r(N)
 
drop if ltd_iss_all_other > 60000 | ltd_iss_all_other < 1000

collapse (mean) count bucket1-bucket16 bucket_2-bucket_14 Qdummy bucket_Q bucket2_Q bucket3_Q bucket4_Q bucket5_Q bucket6_Q bucket7_Q bucket8_Q bucket9_Q ltd_iss_all_other, by(bucket ARRA)

gen logcount = log(count)

reg logcount bucket bucket_2-bucket_8 bucket4-bucket13 if ltd_iss_all_other  > 2000 & ltd_iss_all_other  < 40000 & ARRA == 0 

gen pcount = 0
replace pcount = exp((_b[bucket] * bucket) + (_b[bucket_2] * bucket_2) + (_b[bucket_3] * bucket_3) + (_b[bucket_4] * bucket_4) + (_b[bucket_5] * bucket_5) + (_b[bucket_6] * bucket_6) + (_b[bucket_7] * bucket_7) + (_b[bucket_8] * bucket_8) + _b[_cons]) * exp((e(rmse)^2/2)) if ARRA == 0

replace ltd_iss_all_other  = ltd_iss_all_other  / 1000

twoway connected count bucket if ltd_iss_all_other > 2 & ltd_iss_all_other < 30 & ARRA == 0, msymbol(smcircle) mfcolor(white) || line pcount bucket if ltd_iss_all_other  > 2 & ltd_iss_all_other < 30 & ARRA == 0, lpattern(dash) ytitle("Number of Government-Years") xtitle("Long Term Debt Issued (Millions)") legend(label (1 "Observed") label (2 "Counterfactual") label (3 "2009-2010")) graphregion(color(white))

graph save "Figure 5", replace

 